<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */

    public function __construct(){
        parent::__construct();
        $this->load->helper('form');
    }
	public function index()
	{
       $this->keyword();
    }

    public function keyword() {
        $this->load->view('keyword_test');
    }
    
    public function users() {
    	$this->load->view('users_test');
    }
    
    public function hot() {
    	$this->load->view('hotTest');
    }

    public function page() {
        $html1 = <<<html
html;
 /*       $html2 = <<<html
{"data":null,"errcode":0,"msg":"result is empty","ret":1,"seqid":5889736859719853505}
html;

        $html3 = <<<html
{"data":null,"errcode":0,"msg":"result is empty","ret":1,"seqid":5889736859719853505}
html;
        $html4 = <<<html
{"data":null,"errcode":0,"msg":"result is empty","ret":1,"seqid":5889736859719853505}
html;*/
        $temp_array = array($html1);//, $html2, $html3, $html4);
echo $temp_array[array_rand($temp_array)];
    }

    public function status() {
        $this->load->database();
        $this->load->model('universal/proxy_model');
        $proxy_info = $this->proxy_model->get_proxy_status();

        if(is_null($proxy_info)) {
            echo "没有代理IP!!!<br/>";
            echo "<hr/>";
        } else {
            $temp_array = array();
            if(is_array($proxy_info['all'])){
                $echo_false_tag = FALSE;
                echo "代理IP状态<hr/>";
                foreach($proxy_info['all'] as $key => $row) {
                    if(intval($row['status']) === 1) {
                        $temp_array[$row['status']] = $row['NUM'];
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;可用代理IP ";
                        if($row['NUM'] < 100) {
                            echo "<font style='color: red;font-size: 20;font-weight: bold'> {$row['NUM']} </font> 个&nbsp;&nbsp;&nbsp;&nbsp;";
                        } else {
                            echo "{$row['NUM']} 个&nbsp;&nbsp;&nbsp;&nbsp;";
                        }
                    } else {
                        if($echo_false_tag === FALSE) {
                            echo "<hr/>不可用代理ip</br>";
                            $echo_false_tag = TRUE;
                        }

                        echo "&nbsp;&nbsp;&nbsp;&nbsp;重验证 ".(abs($row['status']) + 1)." 次 {$row['NUM']} 个";
                    }
                }

            }
            if(is_null($proxy_info['all'])) {
                echo "<hr/>60 秒内没有新增代理IP<hr/>";
            } else {
                echo "<hr/>60 秒内新增代理IP &nbsp;&nbsp;";
                foreach($proxy_info['new'] as $result) {
                    if($result['status'] == 1) {
                        echo $result['NUM']."个可用 ";
                    } else {
                        echo $result['NUM']."个不可用 ";
                    }
                }
                echo "<hr/>";
            }
        }
    }

    function curl() {
        $url = 'http://api.crawl.com/get_page/';
        $ch = curl_init();
        $uri = 'http://news.baidu.com/ns?word=%CD%F2%B4%EF&tn=news&from=news&cl=2&rn=20&ct=0';
        $token = '84477250b808234c238b8889b9a18796';
        $post_data = http_build_query(array('token' => $token, 'url' => $uri));
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        //curl_setopt($ch, CURLOPT_PROXYUSERPWD,'hongmai:soften.cn');
        /*if($use_proxy == 20) {
            if($port) {
                $ip = $ip.':'.$port;
            }
            echo "use ip ".$ip."</br>";

            curl_setopt($ch, CURLOPT_PROXY, $ip);
        }*/

        $result = curl_exec($ch);
        if($result) {
             echo $result;
        } else  {
            echo 'CURL ERROR '.curl_error($ch);
        }
        curl_close($ch);
        return $result;
    }

    function test_curl(){
        $url = 'http://www.sina.com';
        $ch = curl_init();
        $uri = 'http://news.baidu.com/ns?word=%CD%F2%B4%EF&tn=news&from=news&cl=2&rn=20&ct=0';
        $token = '84477250b808234c238b8889b9a18796';
        $post_data = http_build_query(array('token' => $token, 'url' => $uri));
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        //curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        //curl_setopt($ch, CURLOPT_PROXYUSERPWD,'hongmai:soften.cn');
        /*if($use_proxy == 20) {
            if($port) {
                $ip = $ip.':'.$port;
            }
            echo "use ip ".$ip."</br>";

            curl_setopt($ch, CURLOPT_PROXY, $ip);
        }*/

        $result = curl_exec($ch);
        if($result) {
            echo $result;
        } else  {
            echo 'CURL ERROR '.curl_error($ch);
        }
        curl_close($ch);
        return $result;
    }

    function token() {
        $this->load->model('universal/system_token_model');
        echo 'System Token:';
        var_dump($this->system_token_model->get_system_token());
    }

    function update_system_token() {
        $this->load->model('universal/system_token_model');
        echo 'Update System Token:';
        var_dump($this->system_token_model->update_system_token());
    }

    function log() {
        echo 'aaaa';
        log_message('notice', 'aaa');
        echo 'bbb';
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */